import React, { Component } from "react";
import "./index.css";
export default class Footer extends Component {
  handlerChange = (event) => {
    this.props.checkAll(event.target.checked);
  };
  handleClearAll = () => {
    this.props.clearAll();
  };
  render() {
    const { todos } = this.props;
    const total = todos.length;
    let selected = 0;
    todos.forEach((element) => {
      if (element.done) {
        selected++;
      }
    });
    let checked = false;
    if (total === selected && total !== 0) checked = true;
    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={checked}
            onChange={this.handlerChange}
          />
        </label>
        <span>
          <span>已完成 {selected}</span> / 全部 {total}
        </span>
        <button onClick={this.handleClearAll} className="btn btn-danger">
          清除已完成任务
        </button>
      </div>
    );
  }
}
